<%@ page language="java" pageEncoding="UTF-8"%>
<%@ page contentType="text/html;charset=utf-8"%>
<%@ page import="java.util.*"%>
<%@ page import="net.sureon.dao.*"%>
<%@page import="net.sureon.common.I18nSupport"%>

<%
	List<Application> all = null;
	all = (List<Application>) request.getAttribute("all");
	String errorMsg = request.getParameter("errorMsg");
%>
<%
int currentPage = (Integer)request.getAttribute("currentPage");
int pageCounter = (Integer)request.getAttribute("pageCounter");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3c.org/TR/1999/REC-html401-19991224/loose.dtd">
<HTML xmlns="http://www.w3.org/1999/xhtml">
	<HEAD>
		<TITLE>我的申请</TITLE>
		<META http-equiv=Content-Type content="text/html; charset=utf-8">
		<script type="text/javascript">
	function deleteApplication() {
		if(confirm("是否删除")) {
			return true;
		}
			else {
			return false;	
		}
	}
	
	function checkDate() {
		sd=document.getElementById("startDate").value;//取得表单填写的时间字符串
		var flag = isdate(sd);
		if(!flag) {
			return false;
		}
		var startDate=new Date(sd.replace(/-/g, "/")); //将表单字符转换成时间类型
		
		ed = document.getElementById("endDate").value;//取得表单填写的时间字符串
		flag = isdate(ed);
		if(!flag) {
			return false;
		}
		var endDate = new Date(ed.replace(/-/g, "/"));
		
		//用当前时间与表单里的时间比较
		if(endDate.getTime()-startDate.getTime() < 0)
		{ 
			alert("结束日期不能够小于开始日期");
			return false;
		} 
		return true;
	}		
	
	function   isdate(strDate){  
        var   strSeparator   =   "-";   //日期分隔符  
        var   strDateArray;  
        var   intYear;  
        var   intMonth;  
        var   intDay;  
        var   boolLeapYear;  
//      var strDate=form1.date.value   //表单中的日期值
        strDateArray   =   strDate.split(strSeparator);  
         
        if(strDateArray.length!=3)    {   alert('日期格式错误'); return   false;   }
         
        intYear   =   parseInt(strDateArray[0],10);  
        intMonth   =   parseInt(strDateArray[1],10);  
        intDay   =   parseInt(strDateArray[2],10);  
         
        if(isNaN(intYear)||isNaN(intMonth)||isNaN(intDay))   {   alert('日期格式错误'); return   false;   }
         
        if(intMonth>12||intMonth<1)    {   alert('日期格式错误'); return   false;   } 
         
        if((intMonth==1||intMonth==3||intMonth==5||intMonth==7||intMonth==8||intMonth==10||intMonth==12)&&(intDay>31||intDay<1))   {   alert('日期格式错误'); return   false;   } 
         
        if((intMonth==4||intMonth==6||intMonth==9||intMonth==11)&&(intDay>30||intDay<1))   {   alert('日期格式错误'); return   false;   }
         
        if(intMonth==2){  
              if(intDay<1)   {   alert('日期格式错误'); return   false;   }
               
              boolLeapYear   =   false;  
              if((intYear%100)==0){  
                    if((intYear%400)==0)   boolLeapYear   =   true;  
              }  
              else{  
                    if((intYear%4)==0)   boolLeapYear   =   true;  
              }  
               
              if(boolLeapYear){  
                    if(intDay>29) {   alert('日期格式错误'); return   false;   }
              }  
              else{  
                    if(intDay>28)  {   alert('日期格式错误'); return   false;   }
              }  
        }  
         
        return   true;  
  } 
	
</script>
<%-- 
		<link rel="stylesheet"
			href="<%=request.getContextPath()%>/css/workSummary.css"
			type="text/css">
--%>

		<META content="MSHTML 6.00.5730.13" name=GENERATOR>
	</HEAD>
	<BODY>
		<jsp:include page="../header.jsp"></jsp:include>
		<DIV>
			<TABLE class=style1 cellSpacing=0 cellPadding=0>
				<TBODY>

					<TR>
						<TD colSpan=2>
							<TABLE class=style5 cellSpacing=0 cellPadding=0>
								<TBODY>
									<TR>
										<TD class=style6 style="TEXT-ALIGN: left" bgColor=#fffbd6>
											<TABLE class=ctl00_ContentPlaceHolder1_Menu1_2
												id=ctl00_ContentPlaceHolder1_Menu1 cellSpacing=0
												cellPadding=0 border=0>
												<TBODY>
													<TR>
														<TD id=ctl00_ContentPlaceHolder1_Menu1n0
															onkeyup=Menu_Key(this) onmouseover=Menu_HoverStatic(this)
															onmouseout=Menu_Unhover(this)>
															<TABLE
																class="ctl00_ContentPlaceHolder1_Menu1_4 ctl00_ContentPlaceHolder1_Menu1_9"
																cellSpacing=0 cellPadding=0 width="100%" border=0>
																<TBODY>
																	<TR>
																		<TD style="WHITE-SPACE: nowrap">
																			<A
																				class="ctl00_ContentPlaceHolder1_Menu1_1 ctl00_ContentPlaceHolder1_Menu1_3 ctl00_ContentPlaceHolder1_Menu1_8"
																				href="<%=request.getContextPath() %>/user/myApplication.do">可编辑的申请</A>
																		</TD>
																	</TR>
																</TBODY>
															</TABLE>
														</TD>
														<TD style="WIDTH: 3px"></TD>
														<TD id=ctl00_ContentPlaceHolder1_Menu1n1
															onkeyup=Menu_Key(this) onmouseover=Menu_HoverStatic(this)
															onmouseout=Menu_Unhover(this)>
															<TABLE class=ctl00_ContentPlaceHolder1_Menu1_4
																cellSpacing=0 cellPadding=0 width="100%" border=0>
																<TBODY>
																	<TR>
																		<TD style="WHITE-SPACE: nowrap">
																			<A
																				class="ctl00_ContentPlaceHolder1_Menu1_1 ctl00_ContentPlaceHolder1_Menu1_3"
																				href="<%=request.getContextPath() %>/user/myConfirmApplication.do">已批准的申请</A>
																		</TD>
																	</TR>
																</TBODY>
															</TABLE>
														</TD>
													</TR>
												</TBODY>
											</TABLE>
										</TD>
									</TR>

									<FORM id=aspnetForm name=aspnetForm
										action="<%=request.getContextPath()%>/user/processApplication.do"
										method=post>
									<TR>
										<TD style="TEXT-ALIGN: left">
											<TABLE class=style5 cellSpacing=0 cellPadding=0>
												<TBODY>
													<TR>
														<TD style="TEXT-ALIGN: left">
															<DIV>
																<TABLE id=ctl00_ContentPlaceHolder1_GridView2
																	style="FONT-SIZE: small; WIDTH: 100%; COLOR: #333333; FONT-FAMILY: Arial; BORDER-COLLAPSE: collapse"
																	cellSpacing=0 cellPadding=4 border=0>
																	<TBODY>
																		<TR
																			style="FONT-WEIGHT: bold; COLOR: white; BACKGROUND-COLOR: #507cd1"
																			align=middle>
																			<TH scope=col style="COLOR: white">
																				申请类别
																			</TH>
																			<TH scope=col style="COLOR: white">
																				开始日期
																			</TH>
																			<TH scope=col style="COLOR: white">
																				结束日期
																			</TH>
																			<TH scope=col style="COLOR: white">
																				累计时长
																			</TH>
																			<TH scope=col style="COLOR: white">
																				说明
																			</TH>
																			<TH scope=col style="COLOR: white">
																				提交时间
																			</TH>
																			<TH scope=col style="COLOR: white">
																				状态
																			</TH>
																			<TH scope=col style="COLOR: white">
																				&nbsp;&nbsp;
																			</TH>
																		</TR>



																		<!-- 通过循环所有的本人所有的申请信息 -->
																		<%
																			if (all == null || all.size() == 0) {
																		%>
																		<%
																			} else {

																				String bgColor=null;
																				String color_a = "#FFFFFF";
																				String color_b = "#EFF3FB";
																				for (int i = 0; i < all.size(); i++) {
																					bgColor = (i%2 == 0)?color_a:color_b;
																					Application app = (Application) all.get(i);
																					java.text.DecimalFormat df = new java.text.DecimalFormat(
																							"####");
																					java.text.SimpleDateFormat sdf = new java.text.SimpleDateFormat(
																							"yyyy-MM-dd HH:mm:ss");
																		%>
																		<TR style="BACKGROUND-COLOR: <%=bgColor%>" align=middle>
																			<TD style="WIDTH: 60px">
																		<%
																				if("Pending".equals(app.getStatus())) {
																					
																		%>				
																			<a href="<%=request.getContextPath() %>/user/myApplication.do?showContent=yes&applicationID=<%=app.getApplicationID() %>"><%=I18nSupport.getMessage(app.getCategory())%></a>
																		<%
																				}else {
																					out.print(I18nSupport.getMessage(app.getCategory()));	
																				}
																		%>
																			</TD>
																			<TD style="WIDTH: 75px"><%=app.getStartDate()%></TD>
																			<TD style="WIDTH: 75px"><%=app.getEndDate()%></TD>
																			<TD style="WIDTH: 60px"><%=df.format(app.getSumTime())%></TD>
																			<TD style="">

																			<%
																			String note = app.getNote();
																			if(note.length() > 73){
																				note = note.substring(0, 70);
																				note = note + "...";
																			}
																			out.print(note);
																			%>
																			
																			</TD>
																			<TD style="WIDTH: 85px"><%=sdf.format(app.getSubmitDate())%></TD>
																			<TD style="WIDTH: 40px"><%=I18nSupport.getMessage(app.getStatus())%></TD>
																			<TD style="WIDTH: 30px">
																			<%
																				if("Rejected".equals(app.getStatus())) {
																				
																			 %>
																				<a
																					href="<%=request.getContextPath()%>/user/deleteApplication.do?applicationID=<%=app.getApplicationID()%>"
																					onclick="return deleteApplication()">删除</a>
																			<%
																				} else {
																				
																			 %>
																			 		删除
																			 <%
																			 	}
																			  %>
																			</TD>
																		</TR>
																		<%
																			}
																			}
																		%>
																	</TBODY>
																</TABLE>
															</DIV>
														</TD>
													</TR>
													<TR>
														<TD style="TEXT-ALIGN: center">
															<jsp:include page="../splitPage.jsp">
															<jsp:param name="url" value="/user/myApplication.do"/>
															<jsp:param name="currentPage" value="<%=currentPage %>"/>
															<jsp:param name="pageCounter" value="<%=pageCounter %>"/>
														</jsp:include>
														</TD>
													</TR>
												</TBODY>
											</TABLE>
								
									<TR>
										<TD>
											<DIV id=ctl00_ContentPlaceHolder1_Panel1>
												<TABLE class=style5 cellSpacing=0 cellPadding=0 width="689"
													height="159">
													<TBODY>
														<TR>
															<TD style="TEXT-ALIGN: left" bgColor=#fffbd6 colSpan=4>
																&nbsp;
															</TD>
														</TR>
														<%
															Application app = (Application)request.getAttribute("app");
															if(app == null) {
															
														 %>
														<TR>
															<TD style="TEXT-ALIGN: left">
																<SPAN id=ctl00_ContentPlaceHolder1_Label4
																	style="FONT-SIZE: small">申请类别：</SPAN>
																<SELECT id=ctl00_ContentPlaceHolder1_DropDownList1
																	style="HEIGHT: 20px" name="category">
																	<OPTION value="Over" selected>
																		加班
																	</OPTION>
																	<OPTION value="Vocation">
																		休假
																	</OPTION>
																	<OPTION value="Leave">
																		请假
																	</OPTION>
																	<OPTION value="BusinessTrip">
																		出差
																	</OPTION>
																</SELECT>
																														</TD>
															<TD style="TEXT-ALIGN: left">
																<SPAN id="xxxxxxxx" style="FONT-SIZE: small">开始日期：</SPAN>
																<INPUT id="startDate"
																	style="FONT-SIZE: small; WIDTH: 86px; HEIGHT: 16px"
																	value="<%=new java.text.SimpleDateFormat("yyyy-MM-dd").format(new Date())%>"
																	name="startDate">
															</TD>
															<TD style="TEXT-ALIGN: left">
																<SPAN id="yyyyy" style="FONT-SIZE: small">结束日期：</SPAN>
																<INPUT id="endDate"
																	style="FONT-SIZE: small; WIDTH: 86px; HEIGHT: 16px"
																	value="<%=new java.text.SimpleDateFormat("yyyy-MM-dd").format(new Date())%>"
																	name="endDate">
															</TD>
															<TD style="TEXT-ALIGN: right">
																<SPAN id=ctl00_ContentPlaceHolder1_Label7
																	style="FONT-SIZE: small">累计时长：</SPAN>
																<INPUT id=ctl00_ContentPlaceHolder1_TextBox3
																	style="FONT-SIZE: small; WIDTH: 30px; HEIGHT: 16px"
																	value=0 name=sumTime>
																<SPAN id=ctl00_ContentPlaceHolder1_Label8
																	style="FONT-SIZE: small">小时</SPAN>
															</TD>
														</TR>
														<TR>
															<TD colSpan=4>
																<TEXTAREA id=ctl00_ContentPlaceHolder1_TextBox4
																	style="FONT-SIZE: small; WIDTH: 99.5%; HEIGHT: 80px"
																	name="note">说明：</TEXTAREA>
															</TD>
														</TR>
													<%
														}
														else {
														
													 %>
													 <TR>
															<TD style="TEXT-ALIGN: left">
																<SPAN id=ctl00_ContentPlaceHolder1_Label4
																	style="FONT-SIZE: small">申请类别：</SPAN>
																<SELECT id=ctl00_ContentPlaceHolder1_DropDownList1
																	style="HEIGHT: 20px" name="category">
																	<%
																		if("Over".equals(app.getCategory())) {
																		
																	 %>	
																	<OPTION value="Over" selected>
																		加班
																	</OPTION>
																	<OPTION value="Vocation">
																		休假
																	</OPTION>
																	<OPTION value="Leave">
																		请假
																	</OPTION>
																	<%
																		} else if("Vocation".equals(app.getCategory())) {
																		
																	 %>
																	 	<OPTION value="Over">
																		加班
																		</OPTION>
																		<OPTION value="Vocation" selected>
																			休假
																		</OPTION>
																		<OPTION value="Leave">
																			请假
																		</OPTION>
																	 <%
																	 	} else {
																	 	
																	  %>
																	  <OPTION value="Over">
																		加班
																		</OPTION>
																		<OPTION value="Vocation">
																			休假
																		</OPTION>
																		<OPTION value="Leave" selected>
																			请假
																		</OPTION>
	
																	  <%
																	  	}		
																	   %>
																	  
																</SELECT>
	
															</TD>
															<TD style="TEXT-ALIGN: left">
																<SPAN id="xxxxxxxx" style="FONT-SIZE: small">开始日期：</SPAN>
																<INPUT id="startDate"
																	style="FONT-SIZE: small; WIDTH: 86px; HEIGHT: 16px"
																	value="<%=new java.text.SimpleDateFormat("yyyy-MM-dd").format(app.getStartDate())%>"
																	name="startDate">
															</TD>
															<TD style="TEXT-ALIGN: left">
																<SPAN id="yyyyy" style="FONT-SIZE: small">结束日期：</SPAN>
																<INPUT id="endDate"
																	style="FONT-SIZE: small; WIDTH: 86px; HEIGHT: 16px"
																	value="<%=new java.text.SimpleDateFormat("yyyy-MM-dd").format(app.getEndDate())%>"
																	name="endDate">
															</TD>
															<TD style="TEXT-ALIGN: right">
																<SPAN id=ctl00_ContentPlaceHolder1_Label7
																	style="FONT-SIZE: small">累计时长：</SPAN>
																<INPUT id=ctl00_ContentPlaceHolder1_TextBox3
																	style="FONT-SIZE: small; WIDTH: 30px; HEIGHT: 16px"
																	value=<%=app.getSumTime() %> name=sumTime>
																<SPAN id=ctl00_ContentPlaceHolder1_Label8
																	style="FONT-SIZE: small">小时</SPAN>
															</TD>
														</TR>
														<TR>
															<TD colSpan=4>
																<TEXTAREA id=ctl00_ContentPlaceHolder1_TextBox4
																	style="FONT-SIZE: small; WIDTH: 99.5%; HEIGHT: 80px"
																	name="note"><%=app.getNote() %></TEXTAREA>
																	<input type="hidden" name="edit" value="edit" />
																	<input type="hidden" name="applicationID" value="<%=app.getApplicationID() %>" />
															</TD>
														</TR>
													 
													 <%
													 	}
													  %>
														<TR>
															<input type="hidden" name="status" value="Pending" />
															<TD style="TEXT-ALIGN: center" colSpan=4>
																<INPUT id=ctl00_ContentPlaceHolder1_Button1 type=submit
																	value="提 交" name=ctl00$ContentPlaceHolder1$Button1
																	onclick="return checkDate();">
																<%=errorMsg== null ? "":errorMsg %>
															</TD>
														</TR>
													</TBODY>
												</TABLE>
											</DIV>
										</TD>
									</TR>
									</FORM>
								</TBODY>
							</TABLE>
						</TD>
					</TR>
				</TBODY>
			</TABLE>
		</DIV>

		<jsp:include page="../footer.jsp"></jsp:include>
	</BODY>
</HTML>
